//
//  PicPickerViewCell.swift
//  sina_yl
//
//  Created by 袁量 on 2017/5/25.
//  Copyright © 2017年 袁量. All rights reserved.
//

import UIKit

class PicPickerViewCell: UICollectionViewCell {

    @IBOutlet weak var addPhoto: UIButton!
    
    @IBOutlet weak var imageView: UIImageView!
    @IBOutlet weak var dismissPhoto: UIButton!
    /// 这里直接设置为图片是不行的，要设置为背景图片
    var image : UIImage? {
        didSet {
            if image != nil {
//                addPhoto.setBackgroundImage(image, for: .normal)
                imageView.image = image
                addPhoto.isUserInteractionEnabled = false
                dismissPhoto.isHidden = false
            } else {
                
//                addPhoto.setBackgroundImage(UIImage(named: "compose_pic_add"), for: .normal)
//                imageView.image = UIImage(named: "compose_pic_add")
                imageView.image = nil 
                 addPhoto.isUserInteractionEnabled = true
                dismissPhoto.isHidden = true 
            }
        }
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    @IBAction func addPhotoClick(_ sender: Any) {
        NotificationCenter.default.post(name: NSNotification.Name(rawValue: PicPickerAddPhotoNote), object: nil)
        
    }
    @IBAction func removePhoto(_ sender: Any) {
        NotificationCenter.default.post(name: NSNotification.Name(rawValue: PicPickerRemovePhotoNote), object: imageView.image)
    }
}
